<template>
  <div class="main">
    <div class="menu">
      <div v-for="(value, key) in menu">
        <div class="menu-title">{{ key }}</div>
        <div class="menu-item" v-for="(cpath, cname) in value" :data-path="cpath">
          <router-link :to="cpath">{{ cname }}</router-link>
        </div>
      </div>
    </div>
    <div class="content">
      <router-view> </router-view>
    </div>
  </div>
</template>
<script lang="ts" setup>
// @ts-ignore
import Prism from 'prismjs'
import 'prismjs/themes/prism.css'
import './common/index.less'
import { onMounted, watch, nextTick } from 'vue'
import { useRouter } from 'vue-router'

const menu = {
  Introduction: {
    'Guide 开发指南': '/guide'
  },
  Basic: {
    'Button 按钮': '/button',
    'Icon 图标': '/icon',
    'Link 文字链接': '/link'
  },
  Form: {
    'Form 表单': '/form',
    'Input 输入框': '/input',
    'Radio 单选框': '/radio',
    'Checkbox 多选框': '/checkbox',
    'Switch 开关': '/switch',
    'Select 选择器': '/select'
  },
  Data: {
    'Table 表格': '/table'
  },
  Feedback: {
    'Message 消息提示': '/message'
  }
}

onMounted(() => {
  Prism.highlightAll()
})

// 当router-view切换时，重新高亮代码
const router = useRouter()
watch(
  () => router.currentRoute.value,
  () => {
    nextTick(() => {
      Prism.highlightAll()
    })
  }
)
</script>
<style scoped lang="less">
.main {
  display: flex;
  height: 95vh;
  justify-content: center;
  width: 1080px;
  margin: auto;
  .menu {
    flex: 1;
    padding-right: 8px; /*为滚动条预留宽度*/
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    &:hover {
      overflow-y: scroll;
    }
  }
  .menu-title {
    color: #999;
    font-size: 12px;
  }
  .menu-item {
    margin: 10px 20px;
    /* router-link会被渲染成a标签 */
    a {
      display: block;
      width: 100%;
      color: #000;
      text-decoration: none;
      padding: 10px 0 10px 20px;
      &:hover {
        color: #409eff; // 转成rgb是(64, 158, 255)
      }
      &.active {
        border-radius: 5px;
        background-color: rgba(64, 158, 255, 0.1);
        color: #409eff;
      }
    }
  }
  .content {
    flex: 4;
    padding: 50px;
    overflow-y: scroll;
  }
  /* 设置滚动条样式 */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
  }
}
</style>
